/**********************************************************************************
Name:  BookedAccountHomeLoanController
Copyright © 2012  Lodha Group
===================================================================================
===================================================================================
Purpose:
-------
Controller For BookedAccountHomeLoan VF page for Customer Portal Users
===================================================================================
===================================================================================
History
-------
VERSION    AUTHOR                DATE             DETAIL              
1.0 -   CG Dev Team          02/05/2012      INITIAL DEVELOPMENT
**********************************************************************************/


public class BookedAccountHomeLoanController {


    public List<Account> bookedaccountlist{get;set;} 
    public List<accountwrapper> wrapperlist{get;set;}
    public String inputvalue{get;set;}
 
    public List<Account> accountfilterlist{get;set;}
    Public Boolean Isfiltered{get;set;}
    Public Boolean Isnotfiltered{get;set;}
    
    public BookedAccountHomeLoanController() {
    
        bookedaccountlist= new List<Account>();
        Bookedaccounts();
        Isnotfiltered=true;
        Isfiltered=false;
        
        inputvalue=ApexPages.currentPage().getParameters().get('inputvalue');
    }
   
     
   
    public class accountwrapper{    
        public String Accountid{get;set;}
        public String AccountName{get;set;}
    } 
   
    public List<accountwrapper> Bookedaccounts()
    {
    
        bookedaccountlist=[select id,Name from Account where RecordType.Name=:'Booked Account' AND IsCustomerPortal!=true];
        wrapperlist=new List<accountwrapper>();
               
        for(Account acc: bookedaccountlist)
            {
                             
                accountwrapper wrapper=new accountwrapper();
                wrapper.Accountid=acc.Id;
                wrapper.AccountName=acc.Name;
                wrapperlist.add(wrapper);
            
            }
        return wrapperlist;
    }
 
 
 public void ViewAll(){
 
 
     bookedaccountlist=[select id,Name from Account where RecordType.Name=:'Booked Account' AND IsCustomerPortal!=true];
        wrapperlist=new List<accountwrapper>();
                   
        for(Account acc: bookedaccountlist)
            {                               
                accountwrapper wrapper=new accountwrapper();
                wrapper.Accountid=acc.Id;
                wrapper.AccountName=acc.Name;
                wrapperlist.add(wrapper);
            
            }
   }
 
 
     public void Searchbyname(){
     
         if(inputvalue!=null && inputvalue!=''){
             inputvalue='%'+inputvalue+'%';
             String recordtype='Booked Account';
             String Querystring='Select Id,Name,FirstName,LastName from Account where (Firstname LIKE '+'\''+inputvalue+'\''+' OR LastName Like '+'\''+inputvalue+'\''+') AND(Account.RecordType.Name='+'\''+recordtype+'\''+')';                          
             accountfilterlist=Database.Query(Querystring);             
                        
             Isfiltered=true;
             Isnotfiltered=false;
             wrapperlist=new List<accountwrapper>();
          for(Account acc: accountfilterlist)
            {                            
                accountwrapper wrapper=new accountwrapper();
                wrapper.Accountid=acc.Id;
                wrapper.AccountName=acc.Name;
                wrapperlist.add(wrapper);            
            }            
          }
          inputvalue=inputvalue.replace('%','');
     }   
     
     
     public static testmethod void testBookedAccountHomeLoanController () {
     
     
            Account a=new Account();
            a.RecordTypeId=[Select id from RecordType where SobjectType='Account' AND Name='Booked Account' Limit 1].Id;
            a.FirstName='Test';
            a.LastName='Account';
            insert a;
        
           BookedAccountHomeLoanController bookedacc=new BookedAccountHomeLoanController();           
           bookedacc.ViewAll();
           bookedacc.inputvalue='TestAccount';
           bookedacc.Searchbyname();
     
     }
    
}